﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Ninject;
using Ninject.Modules;

namespace WP7DSMClient.Services
{
    /// <summary>
    /// Exposes a container as an application service.
    /// </summary>
    public class StandardKernelService : StandardKernel, IApplicationService, IApplicationLifetimeAware
    {
        #region Private members

        static StandardKernelService _current = null;

        #endregion

        #region Public properties

        /// <summary>
        /// Expose the container as a singleton.
        /// </summary>
        public static StandardKernelService Current
        {
            get { return _current; }
        }

        #endregion
        
        #region Constructor

        /// <summary>
        /// Initializes a new instance of the Ninject.StandardKernel class.
        /// </summary>
        /// <param name="modules">The modules to load into the kernel.</param>
        public StandardKernelService(params INinjectModule[] modules) : base(modules)
        {
            _current = this;
        }

        /// <summary>
        /// Initializes a new instance of the Ninject.StandardKernel class.
        /// </summary>
        /// <param name="settings">The configuration to use.</param>
        /// <param name="modules">The modules to load into the kernel.</param>
        public StandardKernelService(INinjectSettings settings, params INinjectModule[] modules)
            : base(settings, modules)
        {
            _current = this;
        }

        #endregion

        #region IApplicationService Members

        /// <summary>
        /// Called by an application in order to initialize the application extension service.
        /// </summary>
        /// <param name="context">Provides information about the application state.</param>
        void IApplicationService.StartService(ApplicationServiceContext context)
        {
            _current = this;
        }

        /// <summary>
        /// Called by an application in order to stop the application extension service.
        /// </summary>
        void IApplicationService.StopService()
        {
            _current = null;
        }

        #endregion

        #region IApplicationLifetimeAware Members

        /// <summary>
        /// Called by an application immediately before the Application.Startup event occurs. 
        /// </summary>
        void IApplicationLifetimeAware.Starting()
        {
            // NOOP
        }

        /// <summary>
        /// Called by an application immediately after the Application.Startup event occurs. 
        /// </summary>
        void IApplicationLifetimeAware.Started()
        {
            // NOOP
        }

        /// <summary>
        /// Called by an application immediately before the Application.Exit event occurs.
        /// </summary>
        void IApplicationLifetimeAware.Exiting()
        {
            // NOOP
        }

        /// <summary>
        /// Called by an application immediately after the Application.Exit event occurs. 
        /// </summary>
        void IApplicationLifetimeAware.Exited()
        {
            // NOOP
        }

        #endregion
    }
}
